<%@page import="java.io.IOException"%>
<%@page import="java.util.*" %>
<%@page import="javax.jdo.PersistenceManager"%>
<%@page import="javax.persistence.PersistenceContext"%>
<%@ page import="com.example.myproject.House" %>
<%@ page import="com.example.myproject.HouseRentalLocations" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ page import="com.example.myproject.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Post Home</title>
</head>
<body>

<%
	House newEntry = new House();
	String name = request.getParameter("name").toString();
	String homeAddress = request.getParameter("homeAddress").toString();
	String email = request.getParameter("email").toString();
	String phoneNo = request.getParameter("phoneNo").toString();
	
	
	int flag=0;
	if(homeAddress.length()>0){
		newEntry.setLatLng(homeAddress);
		if(newEntry.getLat()==0.0 && newEntry.getLng()==0.0){
			flag=1;
			out.write("Invalid Input address");
		}
	
	}
	if(flag==0){
	if(name.length()>0){
		newEntry.setOwnerName(name);		
	}

	if(email.length()>0){
		newEntry.setEmailAddress(email);
	}
	
	if(phoneNo.length()>0){
		newEntry.setPhonoNo(phoneNo);
	}

	PersistenceManager pm = null;
	
	try{
	pm = PMF.get().getPersistenceManager();
	pm.makePersistent(newEntry);
	}catch(Exception e){
		out.write("Crash in PostPage.jsp");
		out.write(e.toString());
	}	
	
  	finally{
  		out.write(":" + name + ":" + homeAddress + ":" + email + ":" + phoneNo + "\n");
  		pm.close();
  		
  	}

  	if(pm != null){
  		out.write("pm is not null\n");  		
  	}

  	out.write("Came Here !\n");
	}

%>

</body>
</html>